package org.qsoft.util;

import java.util.List;
import java.util.Map;

import org.qsoft.ext.TreeNode;


public class TreeUtils {
	
	public static String jsonTreeNode(Map map, String snode)
	{
		TreeNode node = (TreeNode) map.get(snode);
		if(node == null) return null;
		if(node.getChildren().size() == 0) return null;
		
		StringBuffer buffer = new StringBuffer();
		buffer.append("[");
		
		for(int i = 0; i < node.getChildren().size(); i++ )
		{
			TreeNode subNode = (TreeNode) node.getChildren().get(i);
			buffer.append(subNode.toString());
			if(i < node.getChildren().size() - 1)
			{
				buffer.append(",");
			}
			buffer.append("\n");
		}
		
		buffer.append("]");
		//System.out.println(buffer.toString());
		return buffer.toString();
	}

	public List getTreeNodes(Map map, String snode)
	{
		TreeNode node = (TreeNode) map.get(snode);
		
		return node==null?null:node.getChildren();
	}
}
